package com.example.templateapp.ui.base

import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.example.templateapp.util.LoadingDialogFactory

abstract class BaseAppCompatActivity : AppCompatActivity() {


    /**
     * 初始化dataBinding
     */
    protected inline fun <reified T : ViewDataBinding> binding(
        @LayoutRes resId: Int
    ): Lazy<T> = lazy { DataBindingUtil.setContentView<T>(this, resId) }


    /**
     * 初始化加载框
     */
    private val loadingDialog by lazy { LoadingDialogFactory.getDialog(this) }
    protected fun showLoading() {
        loadingDialog.show()
    }

    protected fun disLoading() {
        loadingDialog.dismiss()
    }

    override fun onDestroy() {
        super.onDestroy()
        loadingDialog.recycle()
    }
}